<template>
	<view>
		<title>{{get.title}}</title>
		<view class="cell">
			<view class="cell-title">水站名称</view>
			<view class="cell-content">{{get.station.name}}</view>
		</view>
		<view class="cell">
			<view class="cell-title">发布时间</view>
			<view class="cell-content">{{get.publishTime}}</view>
		</view>
		<navigator url="#" @click="openDoc">
			<view class="cell">
				<view class="cell-title">检测报告</view>
				<view class="cell-content horizontal">
					<view>
						<image class="ext-icon" :src="exts[get.fileList[0].fileExt]" mode="widthFix"></image>
						<text>{{get.fileList[0].fileName}}</text>
					</view>
					<view class="gst">点击预览</view>
				</view>
			</view>
		</navigator>
	</view>
</template>

<script>
	const app = getApp()
	export default {
		onLoad(opts) {
			if(opts.id){
				this.get.id = opts.id 
			}
			uni.request({
				header:{
					Authorization: 'Bearer ' + app.globalData.token, 
				},
				url: app.globalData.curl + 'waterQualityReport/detail/' + opts.id,
				method: 'GET',
				data: {},
				success: res => {
					const {data} = res
					if(data.code==200){
						this.get = data.data
					}else if(data.code==500){
						uni.showToast({
							icon:'none',
							title: data.message,
						});
					}
				},
				fail: (err) => {console.error(err)},
				complete: () => {}
			});
		},
		data() {
			return {
				exts:{
					ppt: '/static/icons/ppt.png',
					pptx: '/static/icons/ppt.png',
					pdf: '/static/icons/PDF.png',
					doc: '/static/icons/word.png',
					docx: '/static/icons/word.png',
					xls: '/static/icons/excel.png',
					xlsx: '/static/icons/excel.png',
					png: '/static/icons/ppt.png',
					txt: '/static/icons/txt.png',
				},
				get:{
					id:1, // 公告ID
					title:"标题", // 标题
					publishTime: "2020-02-10 12:10:00", //发布时间
					station:{
						id: '', // 水站ID
						name:"" // 水站名称
					},
					// 第三方检测报告列表
					fileList:[
						
					]
				}
			}
		},
		methods: {
			openDoc(){
				uni.showLoading({
					title:'加载文件中...',
				})
				uni.downloadFile({
					url:this.get.fileList[0].url,
					complete:()=>{
						uni.hideLoading();
					},
					fail: (err) => {
						uni.showToast({
							icon:'none',
							title: err,
						});
					},
					success:(res)=>{
						const filePath = res.tempFilePath
						uni.openDocument({
							filePath,
							fileType:this.get.fileList[0].fileExt,
							fail: (err) => {
								uni.showToast({
									icon:'none',
									title: err
								});
							},
							
						})
					}
				})
			}
		}
	}
</script>

<style scoped>
	.ext-icon{
		width: 32rpx;
		height: 32rpx;
	}
</style>
